﻿using System;
using System.Windows;
using Microsoft.Phone.Controls;

namespace ElectricityMate
{
    public partial class PastMeasurementsPage : PhoneApplicationPage
    {
        public PastMeasurementsPage()
        {
            InitializeComponent();

            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(PageLoaded);
        }

        private void PageLoaded(object sender, RoutedEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }
        }

        
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            // we don't want to return MeasurementPage. Always to MainPage from here!
            e.Cancel = true;
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            base.OnBackKeyPress(e);
        }
    }
}